Online-Academy
Look, Read, Understand, Apply

Methods for Reversing String

s:str = "Python"
        print(s[::-1])
        # reversing string using Slicing
        # [::-1] means start from beginning to end with step = -1
        reversed_string = s[::-1]
        print(reversed_string)

        reversed_string = ''.join(reversed(s))
        print(reversed_string)

        # Reversing string using for loop
        rev = ""
        for ch in s:
            rev = ch + rev
        print(rev)

        # Reversing string using while loop
        i = len(s) - 1
        while i >= 0:
            print(s[i], end="")
            i -= 1